const children = [

    {
        path:'/security/user',
        name:'SecurityUser',
        component:()=>import('@/views/security/user/user.vue')
    },
    {
        path:'/security/manager',
        name:'SecurityManager',
        component:()=>import('@/views/security/manager/manager.vue')
    },
    {
        path:'/security/admin',
        name:'SecurityAdmin',
        component:()=>import('@/views/security/manager/manager.vue')
    },
    {
        path:'/stock/maintenance',
        name:'StockMaintenance',
        component:()=>import('@/views/stock/maintenance/maintenance.vue')
    },
    {
        path:'/stock/purchase',
        name:'StockPurchase',
        component:()=>import('@/views/stock/purchase/purchase.vue')
    },
    {
        path:'/stock/supplier',
        name:'StockSupplier',
        component:()=>import('@/views/stock/supplier/supplier.vue')
    },
    {
        path:'/stock/manage',
        name:'StockManage',
        component:()=>import('@/views/stock/manage/manage.vue')
    },
    {
        path:'/sell/adjust',
        name:'SellAdjust',
        component:()=>import('@/views/sell/adjust/adjust.vue')
    },
    {
        path:'/sell/statistics',
        name:'SellStatistics',
        component:()=>import('@/views/sell/statistics/statistics.vue')
    },
    {
        path:'/sell/order',
        name:'SellOrder',
        component:()=>import('@/views/sell/order/order.vue')
    },
    {
        path:'/sell/cash',
        name:'SellCash',
        component:()=>import('@/views/sell/cash/cash.vue')
    },
    {
        path:'/sell/vip',
        name:'SellVip',
        component:()=>import('@/views/sell/vip/vip.vue')
    },
    {
        path:'/branch/staff',
        name:'BranchStaff',
        component:()=>import('@/views/branch/staff/staff.vue')
    },
    {
        path:'/branch/information',
        name:'BranchInformation',
        component:()=>import('@/views/branch/information/information.vue')
    },
    {
        path:'/branch/finance',
        name:'BranchFinance',
        component:()=>import('@/views/branch/finance/finance.vue')
    },
];
const routes = [

    //访问路由“/”,自动重定向到"/home"
    {
        path: '/',
        redirect: '/home'
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import('@/views/login.vue')
    },
    {
        path: '/home',
        name: 'Home',
        component: () => import('@/views/home/home.vue'),
        children
    },
    {
        path: '/404',
        name: "NotFound",
        component: () => import('@/views/404.vue')
    }

];

export const existsRoute = (path) => {
    for (let i = 0; i < routes.length; i++) {
        const r = routes[i];
        if (r.path == path) {
            return true;
        }
        if (r.children && r.children.length) {
            for (let k = 0; k < r.children.length; k++) {
                const sr = r.children[k];
                if (sr.path == path) {
                    return true;
                }
            }
        }
    }
    return false;
};

export default routes;